<template>
  <div class="login-container banner_dh">
    <div class="vr-content login-form">
       <div class="title-container">
            <h3 class="title">忘记密码</h3>
          </div>
        <div class="v-steps" style="margin-bottom: 20px;">
          <Steps :current="current">
            <Step title="账号"></Step>
            <Step title="重置密码"></Step>
            <Step title="完成"></Step>
          </Steps>
        </div>
        <!-- step1 -->
        <div class="v-step1 v-wm" v-show="current==0">
          <el-form ref="formValidate" :model="formValidate" :rules="ruleValidate">
              <el-form-item prop="mobile" class="code1">
                <span class="svg-container">
                  <svg-icon icon-class="user" />
                </span>
                  <el-input v-model="formValidate.mobile" placeholder="请输入手机号码"></el-input>
              </el-form-item>
              <el-form-item prop="code" class="vcode">
                <span class="svg-container">
                  <svg-icon icon-class="form" />
                </span>
                  <el-input v-model="formValidate.code" placeholder="验证码" style="width:236px"></el-input>
                  <el-button v-show="sendAuthCode" @click="getAuthCode" >发送短信验证码</el-button>
                  <el-button v-show="!sendAuthCode" style="width:130px" disabled>重新发送(<span class="auth_text_blue">{{auth_time}}</span>s)</el-button>
              </el-form-item>
              <div class="r-btn">
                <el-button type="primary" class="r-btn-1" style="width:100%" @click="next1('formValidate')">下一步</el-button>
              </div>
          </el-form>
        </div>
        <!-- step2 -->
        <div class="v-step2 v-wm" v-show="current==1">
          <el-form ref="formValidate1" :model="formValidate1" :rules="ruleValidate1">
              <el-form-item prop="pwd">
                <span class="svg-container">
                  <svg-icon icon-class="password" />
                </span>
                <el-input
                  :key="passwordType"
                  ref="password"
                  v-model="formValidate1.pwd"
                  :type="passwordType"
                  placeholder="请输入密码"
                  name="password"
                  tabindex="2"
                  auto-complete="on"
                />
                <span class="show-pwd" @click="showPwd">
                  <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
                </span>
              </el-form-item>
              <el-form-item prop="pwd1">
                <span class="svg-container">
                  <svg-icon icon-class="password" />
                </span>
                <el-input :key="passwordType1" :type="passwordType1" ref="password1" v-model="formValidate1.pwd1" placeholder="请输入确认密码"></el-input>
                <span class="show-pwd" @click="showPwd1">
                  <svg-icon :icon-class="passwordType1 === 'password' ? 'eye' : 'eye-open'" />
                </span>
              </el-form-item>
              <div class="r-btn">
                <el-button type="primary" class="r-btn-1" style="width:100%;" @click="next2('formValidate1')">下一步</el-button>
              </div>
          </el-form>
        </div>
        <!-- step3 -->
        <div class="v-step3 v-wm" v-show="current==2" style="margin-top:70px;">
          <div class='vs3-1'>
            密码修改成功！请牢记新密码！
            <div class="vs3-1-1">
              <Icon type="md-checkmark" />
            </div>
            <div class="vs3-1-2">
                <span class="nclr1">{{timeGo}}</span>
                秒自动跳转到
                <span class="nclr2" @click="toClick('/enterpriselogin')">首页</span>
                <!-- 页 -->
            </div>
          </div>
        </div>
      </div>
  </div>
</template>

<script>
import { getMobileCode, forget1, forget2 } from '@/api/user'
import baseSsoUrl from '@/api/baseSsoUrl.js'
export default {
  name: 'Login',
  data() {
    const pwdCheckValidate = (rule, value, callback) => {
      if (this.formValidate1.pwd != "" && value == "") {
        callback(new Error("确认密码不能为空"));
      } else if (this.formValidate1.pwd != value) {
        callback(new Error("两次密码不一致，重新输入"));
      } else {
        callback();
      }
    };
    return {
      passwordType:'password',
      passwordType1:'password',
      current:0,//step页码
      timeGo:'5',
      sendAuthCode:true,/*布尔值，通过v-show控制显示‘获取按钮’还是‘倒计时’ */
      auth_time: 0, /*倒计时 计数器*/
      formValidate:{
          mobile:'',
          code:'',
          userType:'1'
      },
      ruleValidate:{
          mobile: [
              { required: true, message: "手机号码不能为空", trigger: "blur" },
              { type: "string", pattern: /^1[3456789]\d{9}$/, message: "手机号格式不正确", trigger: "blur"}
          ],
          code: [
              { required: true, message: "验证码不能为空", trigger: "blur" },
              { type: "string", pattern: /^\d{6}$/, message: "验证码格式不正确", trigger: "blur"}
          ],
      },
      formValidate1:{
          pwd: "",
          pwd1: "",
      },
      ruleValidate1:{
          pwd: [{ required: true, message: "密码不能为空", trigger: "blur" }],
          pwd1: [
            { required: true, message: "确认密码不能为空", trigger: "blur" },
            { required: true, validator: pwdCheckValidate, trigger: "blur" }
          ],
      },
    };
  },
  watch:{
    current(a,b){
      if(a==2){
        let inteview=setInterval(()=>{
          this.timeGo=this.timeGo-1;
          if(this.timeGo==1){
            this.toClick("/enterpriselogin");
          }
        },1000)
    }}
  },
  methods: {
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    showPwd1() {
      if (this.passwordType1 === 'password') {
        this.passwordType1 = ''
      } else {
        this.passwordType1 = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password1.focus()
      })
    },
    toClick(n){
      this.$router.push({path:n});
    },
    next1(name){
      // console.log(1111)
      // console.log(this.$refs)
      this.$refs[name].validate(valid => {
          if (valid) {
              // console.log("this.formValidate", this.formValidate);
              let params = this.formValidate;
              forget1(params)
              .then((response)=>{
                      // console.log("1111", response);
                      if(response.code == 200){
                          // console.log("success");
                          this.current=1;
                      }else{
                          this.$Message.error(response.msg);
                      }
                  })
                  .catch(function(error) {
                      console.log(error);
                  });
          } else {
              this.$Message.error("表单验证失败!");
          }
      });

    },
    next2(name){
      // console.log(1111)
      // console.log(this.$refs)
      this.$refs[name].validate(valid => {
          if (valid) {
              // console.log("this.formValidate1", this.formValidate1);
              let params = {
                'mobile':this.formValidate.mobile,
                'password':this.formValidate1.pwd1,
                'userType':this.formValidate.userType,
              };
              forget2(params)
                  .then((response)=>{
                      // console.log("1111", response);
                      if(response.code == 200){
                          this.current=2;
                      }else{
                          this.$Message.error(response.msg);
                      }
                  })
                  .catch(function(error) {
                      console.log(error);
                  });
          } else {
              this.$Message.error("表单验证失败!");
          }
      });
    },
    getAuthCode:function () {
        this.$refs.formValidate.validateField("mobile",(a)=>{
            if(a==''){
                this.sendAuthCode = false;
                this.auth_time = 60;
                var auth_timetimer =  setInterval(()=>{
                    this.auth_time--;
                    if(this.auth_time<=0){
                        this.sendAuthCode = true;
                        clearInterval(auth_timetimer);
                    }
                }, 1000);
                let that =this;
                const senddata = ({
                  mobile: this.formValidate.mobile,
                  type: '3'
                })
                getMobileCode(senddata)
                .then(function(response) {
                  //console.log("1111", response);
                  if (response.code == "200") {
                    that.$Message.success("发送成功!");
                    that.sendAuthCode = false;
                    that.auth_time = 60;
                    var auth_timetimer = setInterval(() => {
                      that.auth_time--;
                      if (that.auth_time <= 0) {
                        that.sendAuthCode = true;
                        clearInterval(auth_timetimer);
                      }
                    }, 1000);
                  } else {
                    that.$Message.error(response.msg);
                    that.codeIMGfun();
                  }
                })
                .catch(function(error) {
                  console.log(error);
                });
            }
        });
    },
  }
}
</script>
<style >
  .el-form-item__content{
    text-align: left;
  }
  /*底部*/
  .foot {
    background-color: #404042;
    line-height: 35px;
  }
  .foot_text {
    color: #9e9ea0;
    margin: 0 auto;
    text-align: center;
    padding-top: 30px;
    width: 1200px;
    font-size: 14px;
    display: flex;
    flex-flow: nowrap;
    justify-content: space-around;
  }
  .foot_img img {
    /* float: right; */
    /* position: relative; */
    /* bottom: 127px;
    right: 80px; */
    width: 120px;
    height: 120px;
  }
  .header{
    width: 1200px;
    margin: auto;
    overflow: hidden;
  }.header div{
     float: left;
   }
  .student_logo{
    margin: 20px 0px 10px 0px;
  }
  .student_title{
    width: 260px;
    height: 19px;
    font-weight: bold;
    color: #2B5C8a;
    font-size: 20px;
    margin: 5px 0 0 40px;
  }
  .student_icon{
    float: right !important;
    margin-right: 10px;
    margin-top: 50px;
  }
  .student_icon img{
    width: 35px;
    height: 35px;
  }
  .header_background{
    background-color: #2c5c8a;
  }
  .nav{
    width: 1200px;
    margin: auto;
    background-color: #2c5c8a;
    overflow: hidden;
  }
  .nav li{
    list-style: none;
    float: left;
    height: 38px;
    margin-right: 60px;
    margin-left: 20px;
  }
  .nav li a{
    font-size: 20px;
    color: #ffffff;
    font-weight: bold;
  }
  .demonstration2 {
    display: block;
    font-size: 16px;
    margin-top: 53px;
    text-align: center;
  }
  .demonstration3 {
    display: block;
    font-size: 16px;
    margin-top: 52px;
    text-align: center;
  }
  .loginrk{
    display: block;
    font-size: 16px;
    margin-top: 42px;
    float: right;
    margin-left: 100px;
  }
  .loginrk div{
    margin-left: 20px;
    margin-top: 0px;
  }
    .code1{
    position:relative;
  }
  .code2{
    position:absolute;
    right: 33px;
    top: 5.6px;
    height: 37px;
    border-radius:3px;

  }
  .topbar{
    margin-top: 20px;
    width: 100%;
    background:rgb(240 242 245 / 0);
  }
.login-container .is-active{
  color:#ffd04b !important;
  background:hsla(0,0%,5%,.0)!important;
}
.login-container .el-menu-item:visited{
  color:#ffd04b !important;
  background:hsla(0,0%,5%,.0)!important;
}
.login-container .el-menu-item:hover{
  color:#ffd04b !important;
  background:hsla(0,0%,5%,.0)!important;
}
.regbar{
     float: right;
      line-height: 60px;
  margin-right: 20px;
  font-size: 16px;
    color: #29d;
}
.el-main{
  padding: 60px 0px 0px 0px !important;
}
.login-container .el-menu {
  background:hsla(0,0%,5%,.01);
}
 .login-container .el-menu--horizontal{
    border-bottom: 0px !important;
  }
 .login-container .footitem{display: block;
    color: #a4a4a4;
    margin-top: 14px;
  font-size: 14px;}
  .v-step1 .el-button{
      background: #409eff;
    border: 1px solid #409eff;
    color: #ffff;
  }
  .v-step1 .el-button.is-disabled{
          color: #C0C4CC;
    cursor: not-allowed;
    background-image: none;
    background-color: #FFF;
    border-color: #EBEEF5;
    width:140px!important;
    margin-left:0;
  }
</style>
<style lang="scss" scoped>
      .vr-top{
        // position: absolute;
        // top: 11%;
        // right: 25%;
        color: #B2B4B6;
        font-size: 14px;
        padding-right: 10px;
        border-right: 2px solid #B2B4B6;
        line-height: 16px;
        &:hover{
          cursor: pointer;
        }
      }
      .vr-content{
        width: 460px;
        // position: absolute;
        // left: 38%;
        // top: 26%;
        bottom: 0;
        margin: auto 0 auto -170px;
        max-height: 475px;
        text-align: left;
        font-size: 22px;
        .v-steps{
          margin: 0 auto;
          width: 90%;
          margin-bottom: 40px;
        }
        .ivu-form-item-content{
          font-size: 14px !important;
        }
        .ivu-input{
          font-size: 14px !important;
        }
        .v-wm{
          width: 100%;
          margin: 30px 0px 0 0px;
        }
        .row{
          text-align: center;
          width: 85%;
          margin: 0 auto;
          margin-top:20px;
          .r-btn{
            text-align:center;
            margin-left: 95px;
            .r-btn-1{
              width:256px;
              height:34px;
              background-color: #0F8EE9;
              border-radius: 30px;
            }
          }
        }
        /* step1 */
        .v-step1{
          text-align: center;

        }
        /* step2 */
        .v-step2{
          text-align: center;

        }
        /* step3 */
        .v-step3{
          text-align: center;
          .vs3-1{
            width:200px;
            height:20px;
            margin:0 auto;
            text-align: center;
            position:relative;
            font-size:14px;
            color:black;
            margin-left: 130px;
            .vs3-1-1{
              width:20px;
              height:20px;
              border-radius:10px;
              line-height:40px;
              background-color:RGB(77,192,0);
              color:white;
              position:absolute;
              left:-30px;
              top:0px;
              color:white;
              line-height:22px
            }
            .vs3-1-2{
              width:175px;
              height:20px;
              margin:0 auto;
              text-align: center;
              position:absolute;
              left:0px;
              top:30px;
              color:RGB(187,187,187);
              font-size:13px;
              .nclr1{
                color:RGB(231,76,76)
              }
              .nclr2{
                color:#0F8EE9;
                cursor: pointer;
              }
            }
          }
        }
      }
      .vr-info{
        width: 100%;
        position: absolute;
        bottom: 15px;
        text-align: center;
        color: #999;
        font-size: 14px;
      }
</style>
<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg:#fff;
$light_gray:#fff;
$cursor: #aaa;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;

    input {
      background: #fff;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      /*padding: 12px 5px 12px 15px;*/
      color: #888888;
      height: 37px;
      caret-color: $cursor;
      border-radius: 4px;

      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #454545;
  }
  .ivu-steps .ivu-steps-title,.ivu-steps .ivu-steps-head{
    background: #f0f7fd;
  }
}
</style>

<style lang="scss" scoped>
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;

.login-container {
  min-height: 100%;
  width: 100%;
  background-color: $bg;
  overflow: hidden;
  .diBox{
    width: 100%;
      position: relative;
      bottom:0;left: 0;
      .foot_text{
        width: 1200px;
        margin:0 auto;
      }
  }
  .login-form {
      margin-bottom: 50px;
      position: relative;
          width: 520px;
    max-width: 100%;
    height: 360px;
    padding: 36px 35px;
      margin-top:  6% ;
      margin-left:  50% ;
      margin-right:  7% ;
      padding-top: 0;
      overflow: hidden;
      background-color: #f0f7fd;
      box-shadow: 0px 0px 20px 5px #60b5da;

    }

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      font-size: 26px;
      color: #495d64;
      margin: 20px auto 20px auto;
      text-align: center;
      font-weight: bold;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
   .banner_dh{
    background-size: 1920px 650px;
    background-repeat: no-repeat;
     background: #FFFFFF;
    width: 100%;
    /*height: 650px;*/
    min-width: 1200px;
    position: relative;
    z-index: 1;
        display: flex;
    flex-flow: column;
    justify-content: space-between;
  }
</style>
